﻿@inherits BaseComponent

@if (Model != null && Model.QueryColumns != null && Model.QueryColumns.Count > 0) {
    if (Model.QueryColumns.Count > 3) {
        var showCount = 3;
        var count = Model.QueryColumns.Count;
        if (count > showCount)
            count = _expand ? count : showCount;
        var offset = _expand ? (3 - count % 4) * 6 : 0;
        var moreClass = CssBuilder.Default("kui-query-more").AddClass("expand", _expand).BuildClass();
        <div class="@moreClass">
            <QueryDataForm Model="Model.QueryData">
                <AntRow>
                    @for (var i = 0; i < count; i++) {
                        var item = Model.QueryColumns[i];
                        var itemName = Language.GetFieldName(item, Model.DataType);
                        <AntCol Span="6">
                            <FieldItem Label="@itemName">
                                <QueryItem Item="item" Data="context" OnSearch="OnItemSearchAsync" />
                            </FieldItem>
                        </AntCol>
                    }
                    <AntCol Span="6" Offset="offset" Style="text-align:right;">
                        <div class="ant-form-item">
                            <KButton Name="@Language.Search" Icon="search" OnClick="OnSearchAsync" />
                            @if (IsAdvSearch) {
                                <KButton Name="@Language.AdvSearch" OnClick="ShowAdvSearch" />
                            }
                            <KButton Name="@Language.Reset" Icon="undo" Type="ButtonType.Default" OnClick="OnReset" Title="@Language.TipReset" />
                            @if (Model.QueryColumns.Count > showCount) {
                                <a class="ant-btn-link" style="margin-left:8px;font-size:12px;" @onclick="()=>{_expand=!_expand;}">
                                    <Icon Type="@(_expand ? "up" : "down")"></Icon> @(_expand ? Language[Language.Collapse] : Language[Language.Expand])
                                </a>
                            }
                        </div>
                    </AntCol>
                </AntRow>
            </QueryDataForm>
        </div>
    } else {
        <QueryDataForm Model="Model.QueryData" Layout="@FormLayout.Inline">
            @for (var i = 0; i < Model.QueryColumns.Count; i++) {
                var item = Model.QueryColumns[i];
                var itemName = Language.GetFieldName(item, Model.DataType);
                <FieldItem Label="@itemName">
                    <QueryItem IsInline Item="item" Data="context" OnSearch="OnItemSearchAsync" />
                </FieldItem>
            }
            <div class="kui-query-btn">
                <KButton Name="@Language.Search" Icon="search" OnClick="OnSearchAsync" />
                @if (IsAdvSearch) {
                    <KButton Name="@Language.AdvSearch" OnClick="ShowAdvSearch" />
                }
                <KButton Name="@Language.Reset" Icon="undo" Type="ButtonType.Default" OnClick="OnReset" Title="@Language.TipReset" />
            </div>
        </QueryDataForm>
    } 
}